﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using WinFormsAppTest.Service;

namespace WinFormsAppTest.Control
{
    public partial class UserExamSearchControl : UserControl
    {
        private int userid;
        public UserExamSearchControl()
        {
            InitializeComponent();
        }

        public UserExamSearchControl(int id)
        {
            userid = id;
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timelabel.Text = DateTime.Now.ToString("G");
        }

        private void SearchControl_Load(object sender, EventArgs e)
        {
            //调整时间控件
            timer1.Interval = 1000;
            timer1.Start();
            //

            //调整界面的大小使得所有的控件显示出来
            this.Size = new Size(1029, 501);
            //

            //开始添加表格中的数据
            //FormService formservice = new FormService();
            //ExamdataGridView = formservice.Form_Examdata_Loading(ExamdataGridView);
            DataGridViewClass dataGridViewClass = new DataGridViewClass();
            ExamdataGridView = dataGridViewClass.GetExamDataByUserId(ExamdataGridView, userid);
            //
        }

        private void searchtextBox_Enter(object sender, EventArgs e)
        {
            if (searchtextBox.Text == "请输入搜索内容")
                searchtextBox.Text = "";
            searchtextBox.ForeColor = Color.Black;
        }

        private void searchtextBox_Leave(object sender, EventArgs e)
        {
            if (searchtextBox.Text == "")
            {
                searchtextBox.Text = "请输入搜索内容";
                searchtextBox.ForeColor = Color.Gray;
            }
        }

        private void searchbutton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(searchtextBox.Text)
                || searchcomboBox.SelectedItem == null)//判断复选框是否选中
            {
                ExamdataGridView.Rows.Clear();
                DataGridViewClass dataGridView = new DataGridViewClass();
                ExamdataGridView = dataGridView.GetExamDataByUserId(ExamdataGridView, userid);
            }
            else
            {
                string combox = searchcomboBox.SelectedItem.ToString();
                ExamdataGridView.Rows.Clear();
                //if (int.TryParse(searchtextBox.Text, out int number)
                //    && combox == "考核编号")
                //{
                //    if (number != 0 && searchtextBox.Text != "请输入搜索内容")
                //    {
                //        DataGridViewClass dataGridView = new DataGridViewClass();
                //        ExamdataGridView = dataGridView.GetExamDataById(ExamdataGridView, number);
                //    }
                //    else
                //    {
                //        DataGridViewClass dataGridView = new DataGridViewClass();
                //        ExamdataGridView = dataGridView.GetExamData(ExamdataGridView);
                //    }

                //}
                //else 

                if (combox == "奖惩情况")
                {
                    if (searchtextBox.Text != "" && searchtextBox.Text != "请输入搜索内容")
                    {
                        DataGridViewClass dataGridView = new DataGridViewClass();
                        ExamdataGridView = dataGridView.GetExamDataByState(ExamdataGridView, searchtextBox.Text);
                    }
                    else
                    {
                        DataGridViewClass dataGridView = new DataGridViewClass();
                        ExamdataGridView = dataGridView.GetExamDataById(ExamdataGridView, userid);
                    }

                }
                //else if (combox == "员工编号")
                //{
                //    if (number != 0 && searchtextBox.Text != "请输入搜索内容")
                //    {
                //        //MessageBox.Show(""+number);
                //        DataGridViewClass dataGridView = new DataGridViewClass();
                //        ExamdataGridView = dataGridView.GetExamDataByUserId(ExamdataGridView, number);
                //    }
                //    else
                //    {
                //        DataGridViewClass dataGridView = new DataGridViewClass();
                //        ExamdataGridView = dataGridView.GetExamData(ExamdataGridView);
                //    }

                //}
                //else
                //{
                //    DataGridViewClass dataGridView = new DataGridViewClass();
                //    ExamdataGridView = dataGridView.GetExamData(ExamdataGridView);
                //}
            }
        }
    }
}
